import {BaseInfo} from "./ModelInfoWindow.js";

export class MouseEvent {
    static getClickObject(event, camera, scene) {
        return new Promise((resolve,reject)=>{
            let mouse = new THREE.Vector2();
            mouse.x = (event.offsetX / window.innerWidth ) * 2 - 1;
            mouse.y = -(event.offsetY / window.innerHeight) * 2 + 1;

            event.preventDefault();
            let vector = new THREE.Vector3();
            vector.set(mouse.x, mouse.y, 0.5);
            vector.unproject(camera);
            let raycaster = new THREE.Raycaster(camera.position, vector.sub(camera.position).normalize());
            let intersects = raycaster.intersectObjects(scene.children, true);
            if (intersects.length > 0) {
                let selected = intersects[0];
                resolve(selected);
            }
            reject("can't get object")
        })
    }
    clickEvent(){}
    hoverEvenet(){}
}

export class BaseMouseEvent extends MouseEvent{
    async clickEvent(model){
        let baseInfo = new BaseInfo()
        baseInfo.displayWindow()
    }
}
